package com.itouch.bracelet.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.itouch.bracelet.R;
import com.itouch.bracelet.bean.PSport;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

/**
 * cocoaSJ
 */
public class PSportAdapter extends BaseAdapter 
		 {
	private ArrayList<PSport> list;
	private Context context;
	private ImageLoader  imageLoader = ImageLoader.getInstance();
	private LayoutInflater infalter;
	private DisplayImageOptions options;
	
	
	public PSportAdapter(Context context, ArrayList<PSport> list) {
		this.list = list;
		this.context = context;
		  infalter = LayoutInflater.from(context);
		  options = new DisplayImageOptions.Builder()
			.imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
			.showImageOnLoading(R.drawable.default_face)
			.showImageForEmptyUri(R.drawable.default_face)
			
			.displayer(new RoundedBitmapDisplayer(5))
			.showImageOnFail(R.drawable.default_face).cacheInMemory(true)
			.cacheOnDisc(true).considerExifParams(true)
			.bitmapConfig(Bitmap.Config.RGB_565).build();
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public PSport getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View converView, ViewGroup viewGrop) {
		// TODO Auto-generated method stub
		ViewHolder vh = null;
		if (converView == null) {
			vh = new ViewHolder();
			converView =infalter.inflate(
					R.layout.adapter_item_sport, viewGrop,false);
			vh.start_time = (TextView) converView.findViewById(R.id.start_time);
			 vh.content = (TextView) converView.findViewById(R.id.content);
			 vh.next_time = (TextView) converView.findViewById(R.id.next_time);
			 vh.avat = (ImageView) converView.findViewById(R.id.avat);
			
			converView.setTag(vh);
		} else {
			vh = (ViewHolder) converView.getTag();
		}
		 vh.avat .setImageResource(R.drawable.m_avatar);
		
		PSport bean = getItem(position);
		
		vh.start_time.setText("开始时间:"+bean.getStartTime()+"");
		vh.next_time.setText("结束时间:"+bean.getEndTime()+"");
		
		return converView;
	}

	class ViewHolder {
		public TextView start_time;
		public TextView next_time;
		public TextView content;
		public ImageView avat;
	}

}
